package com.yjhh.chdataservice.controller;

import com.yjhh.chdataservice.beans.*;
import com.yjhh.chdataservice.except.YJHHException;
import com.yjhh.chdataservice.service.DemoProService;
import com.yjhh.chdataservice.util.CommonResultData;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * PROJ_PUBLIC_INF  公共服务表
 * PROJ_DEMONSTRATIONITEM_INF 示范项目基础信息表
 * PROJ_COMMUNITY_INF 社区信息表
 * PROJ_FACILITIES_INF 项目附件类型表
 * PROJ_ATTACH_INF 项目附件表
 */
@Api(tags = "示范项目模块相关接口")
@RestController
@RequestMapping(value = "/service/fzjc/demoPro")
@Log4j2
public class DemoProjectControler {

    @Autowired
    private DemoProService demoProService;


    @ApiOperation(value = "获取示范项目基础信息列表", notes = "获取示范项目基础信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000"),
            @ApiImplicitParam(name = "pointName", value = "安置点名称", required = false, paramType = "query", dataType = "String", defaultValue = ""),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getDemoProBaseInfoList", method = RequestMethod.GET)
    public CommonResultData<List<DemoProBaseInfoVo>> getDemoProBaseInfoList(@RequestParam String areaCode,@RequestParam String pointName) {
        CommonResultData<List<DemoProBaseInfoVo>> result = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            result = demoProService.getDemoProBaseInfoList(areaCode,pointName);
            result.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getDemoProBaseInfoList", e);
            result = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return result;
    }

    @ApiOperation(value = "获取示范项目详细信息", notes = "获取示范项目详细信息")
    @ApiImplicitParam(name = "demonstrationitemId", value = "示范项目ID", required = true, paramType = "query", dataType = "String", defaultValue = "76caee2a-1961-444f-b27d-10ed7cfa80b9")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getDemoProDetailInfo", method = RequestMethod.GET)
    public CommonResultData<DemoProDetailInfoVo> getDemoProDetailInfo(@RequestParam String demonstrationitemId) {
        CommonResultData<DemoProDetailInfoVo> result = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            result = demoProService.getDemoProDetailInfo(demonstrationitemId);
            result.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getDemoProDetailInfo", e);
            result = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return result;
    }

    @ApiOperation(value = "获取示范项目附件信息列表", notes = "获取示范项目附件信息列表")
    @ApiImplicitParam(name = "demonstrationitemId", value = "示范项目ID", required = true, paramType = "query", dataType = "String", defaultValue = "8161d24f-7ca0-4b80-a46a-fc5c13e365dd")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getDemoProAttachInfoList", method = RequestMethod.GET)
    public CommonResultData<List<DemoProAttachVo>> getDemoProAttachInfoList(@RequestParam String demonstrationitemId) {
        CommonResultData<List<DemoProAttachVo>> result = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            result = demoProService.getDemoProAttachInfoList(demonstrationitemId);
            result.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getDemoProAttachInfoList", e);
            result = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return result;
    }

    @ApiOperation(value = "示范项目总览统计接口", notes = "示范项目总览统计接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue =
                    "610000000000"),
            @ApiImplicitParam(name = "category",
                    value = "统计类型（0：所有类型，1：交通位置，2：行政位置，3：安置规模，4：区域分布，5：产业类型，6：就业岗位，7：产业脱贫10+，8：公共服务，9：一站式服务）",
                    required = true, paramType = "query", dataType = "String", defaultValue = "1"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/statisticsDemoPro", method = RequestMethod.GET)
    public CommonResultData<StatisticsDemoProVo> statisticsDemoPro(@RequestParam String areaCode, @RequestParam String category) {
        CommonResultData<StatisticsDemoProVo> result = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            result = demoProService.statisticsDemoPro(areaCode, category);
            result.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("statisticsDemoPro", e);
            result = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return result;
    }

}
